package com.khoayang.littlefighterchaos.game;

import java.util.ArrayList;
import java.util.Random;

import org.cocos2d.types.CGPoint;

import com.khoayang.littlefighterchaos.game.GamePad.KEY;

public class DummyAI extends AI{

	public DummyAI(CharacterGame character, ArrayList<CharacterGame> otherCharacters) {
		super(character, otherCharacters);
	}

	
	@Override
	public void update() {
		_Time ++;
		Random r = new Random();
		
		if(_Time == _AttackSkillDuration){
			int nSkills = _Character.get_State().get_SkillList().size();
			BaseSkill skill;
			do{
			skill = _Character.get_State().get_SkillList().get(r.nextInt(nSkills));
			}while(!(skill instanceof AttackingSkill));
			_Character.startAction(skill.get_SkillName());	
			_AttackSkillDuration = r.nextInt(MAX_ATTACK_SKILL_DURATION);
			return;
		}
		
		if(_Time <= _MoveSkillDuration)
		{
			CGPoint pos = _Character.get_Position();
			if(pos.x >= _WinSize.width){
				_RandomDirection = 2;//move to left
			}else if(pos.x <= 0){
				_RandomDirection = 3;//move to right
			}else if(pos.y >= _WinSize.height/3){
				_RandomDirection = 1;//move down
			}else if(pos.y <= _Character.get_Sprite().getContentSize().getHeight()/2){
				_RandomDirection = 0;//move up
			}
			ArrayList<KEY> keyState = new ArrayList<KEY>();
			
			switch (_RandomDirection) {
			case 0:
				keyState.add(KEY.UP);
				break;
			case 1:
				keyState.add(KEY.DOWN);
				break;
			case 2:
				keyState.add(KEY.LEFT);
				break;
			case 3:
				keyState.add(KEY.RIGHT);
				break;
			case 4:
				keyState.add(KEY.JUMP);
				break;
			default:
				break;
			}
			_Character.update(keyState);
		}
		else
		{
			if(_RandomDirection == 4){
				_Character.startAction("Jump");
			}
			else
			{
				_Character.startAction("Walk");
			}
			CGPoint pos = _Character.get_Position();
			
			_RandomDirection = r.nextInt(5);
			_MoveSkillDuration = r.nextInt(MAX_MOVE_SKILL_DURATION);
			_Time = 0;	
		}		
	}
}
